package com.neal.utils;

import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;

import java.io.IOException;
import java.util.Properties;

/**
 * @author Neal
 * @createdDate 2014-5-26
 */
public class ResourcesUtils {

    private static PathMatchingResourcePatternResolver pathMatchingResourcePatternResolver = new PathMatchingResourcePatternResolver();
    
    /**
     * return resources by location pattern
     */
    public static Resource[] getResources(String locationPattern) throws IOException {
        return pathMatchingResourcePatternResolver.getResources(locationPattern);
    }
    
    /**
     * get properties by location pattern
     */
    public static Properties getProperties(String locationPattern) throws IOException{
        Resource[] resources = getResources(locationPattern);
        Properties properties = new Properties();
        for (Resource resource : resources) {
            properties.load(resource.getInputStream());
        }
        return properties;
    }
    
}
